package com.itheima.controller.admin;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.OrderStatusDTO;
import com.itheima.service.OrderService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
@Slf4j
@Api(tags = "预约管理")
@RequiredArgsConstructor
public class OrderController {
    private final OrderService orderService;
    /**
     * 预约分页查询
     * @param queryPageBean
     * @return
     */
    @PostMapping("/findPage")
    public PageResult OrderPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询{}", queryPageBean);
        return orderService.pageQuery(queryPageBean);
    }
    /**
     * 修改预约状态
     * @param orderStatusDTO
     * @return
     */
    @PostMapping("/update")
    private Result updateOrderStatus(@RequestBody OrderStatusDTO orderStatusDTO){
        log.info("更新订单状态: id={}, status={}", orderStatusDTO.getId(),orderStatusDTO.getOrderStatus());
        Result result = new Result();
        try {
            orderService.updateOrderStatus(orderStatusDTO);
        } catch (Exception e) {
            result.setFlag(false);
            result.setMessage(MessageConstant.UPDATE_ORDER_FAIL);
            return result;
        }
        result.setFlag(true);
        result.setMessage(MessageConstant.UPDATE_ORDER_SUCCESS);
        return result;
    }
}
